<template>
  <div class="salesclerk-container">
    <div class="salesclerk-search">
      <span class="page-title">店员列表</span>
      <el-input placeholder="请输入搜索内容" v-model="keyWords" class="input-with-select search-keyword">
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="店员姓名" value="1"></el-option>
          <el-option label="门店编号" value="2"></el-option>
        </el-select>
      </el-input>
      <el-button type="primary" size="small" icon="el-icon-search" @click="searchSalesclerk">搜索</el-button>
      <el-button type="info" size="small" class="search-keyword-reset" plain @click="resetSearch">重置</el-button>
    </div>

    <div class="salesclerk-table">
      <el-table ref="multipleTable" :data="salesclerkData" border stripe fit v-loading="listLoading"
                :row-style="{height:'50px'}" :header-row-style="{height:'40px'}" @filter-change="filterChange">
        <el-table-column prop="id" label="id" width="80">
          <template slot-scope="scope">
            {{scope.row.id}}
          </template>
        </el-table-column>
        <el-table-column label="门店编号" width="200">
          <template slot-scope="scope">
            {{scope.row.shopNum}}
          </template>
        </el-table-column>
        <el-table-column label="店员姓名" width="150">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>
        <el-table-column label="身份证号码" width="180">
          <template slot-scope="scope">
            {{scope.row.userCardNumber}}
          </template>
        </el-table-column>
        <el-table-column label="邀请状态" width="120"
                         :filters="[{ text: '邀请中', value: 0 }, { text: '邀请通过', value: 1 }, { text: '邀请失败', value: 2 }]"
                         :filter-multiple="false" column-key="status"
                         filter-placement="bottom-end" prop="status">
          <template slot-scope="scope">
            <span>{{scope.row.status | changeStatus}}</span>
          </template>
        </el-table-column>
        <el-table-column label="生成时间" width="160">
          <template slot-scope="scope">
            <span v-if="scope.row.time">{{scope.row.time | formatTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="200" fixed="right">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" style="width: 96px" @click="handleLook(scope.row)"
                       v-if="checkPermissionPoints(3) == 1">查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :type="1" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                  @pagination="getSalesclerkList"/>
    </div>

    <!--查看-->
    <el-dialog title="详细信息" :visible.sync="dialogLookVisible" width="960px" class="salesclerk-dialog look-dialog">
      <el-form ref="form" label-width="140px" size="mini">
        <el-form-item label="门店编号：">
          <span>{{salesclerk.shopNum}}</span>
        </el-form-item>
        <el-form-item label="店员姓名：">
          <span>{{salesclerk.userName}}</span>
        </el-form-item>
        <el-form-item label="身份证号码：">
          <span>{{salesclerk.userCardNumber}}</span>
        </el-form-item>
        <el-form-item label="邀请状态：">
          <span>{{salesclerk.status | changeStatus}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" style="width: 96px" @click="dialogLookVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
  import Pagination from '@/components/Pagination';
  import {mapGetters} from 'vuex';
  import {permissionPoints} from '@/utils/permission';
  import {formatDate} from "@/utils/index";
  import {geSalesclerkDetail, getInitSalesclerkList} from "../../../api/shop/shop";

  export default {
    name: "salesclerk",
    computed: {
      ...mapGetters([
        'points'
      ])
    },
    components: {
      Pagination
    },
    data() {
      return {
        total: 0,
        listQuery: {
          page: 1,
          limit: 20,
          userName: '',
          shopNum: '',
          status: ''
        },
        keyWords: '',
        select: '1',
        listLoading: false,
        dialogLookVisible: false,
        salesclerkData: [],
        salesclerk: {}
      }
    },
    created() {
      this.getSalesclerkList();
    },
    methods: {
      filterChange(value) {//过滤
        this.listQuery.status = String(value.status);
        this.listQuery.page = 1;
        this.getSalesclerkList();
      },
      searchSalesclerk() {//搜索
        if (this.keyWords == '' || this.keyWords == undefined) {
          return this.$message.info({message: '请输入搜索内容', duration: 1000});
        }
        this.listQuery.userName = '';
        this.listQuery.shopNum = '';
        this.listQuery.status = '';
        if (this.select == 1) {
          this.listQuery.userName = this.keyWords;
        } else if (this.select == 2) {
          this.listQuery.shopNum = this.keyWords;
        }
        this.listQuery.page = 1;
        this.getSalesclerkList();
      },
      resetSearch() {
        this.select = '1';
        this.keyWords = '';
        this.listQuery.userName = '';
        this.listQuery.shopNum = '';
        this.listQuery.status = '';
        this.listQuery.page = 1;
        this.$refs.multipleTable.clearFilter();
        this.getSalesclerkList();
      },
      getSalesclerkList() {
        this.listLoading = true;
        getInitSalesclerkList(this.listQuery).then((res) => {
          this.listLoading = false;
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            const {items, totalRecord} = retObj.data;
            this.total = totalRecord;
            this.salesclerkData = items;
          }
        }).catch(() => {
          this.listLoading = false;
        })
      },
      checkPermissionPoints(type) {
        let pointObj = this.points.salesclerk;
        return permissionPoints(type, pointObj);
      },
      handleLook(row) {
        this.dialogLookVisible = true;
        geSalesclerkDetail(row.id).then((res) => {
          let retObj = res;
          if (retObj.code == 0 && retObj.data != null) {
            this.salesclerk = retObj.data;
          }
        })
      }
    },
    filters: {
      formatTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss');
      },
      changeStatus(type) {
        if (type == 0) {
          return '邀请中';
        } else if (type == 1) {
          return '邀请通过';
        } else if (type == 2) {
          return '邀请失败';
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .salesclerk-container {
    .salesclerk-search {
      display: flex;
      align-items: center;
      width: 100%;
      height: 80px;
      .page-title {
        padding-left: 18px;
        min-width: 160px;
        text-align: left;
        font-size: 18px;
        font-weight: bold;
        color: rgba(61, 68, 77, 1);
      }
      .search-keyword {
        margin-right: 24px;
        width: 470px;
        > > > .el-select .el-input {
          width: 110px;
        }
        > > > .el-input-group__prepend {
          background-color: #fff;
        }
      }
      .search-keyword-reset {
        margin-right: 36px;
      }
      .excel-inout-box {
        margin-left: auto;
        margin-right: 18px;
      }
    }

    .salesclerk-table {
      width: 98%;
      margin-left: 18px;
      > > > .el-table td, .el-table th {
        padding: 6px 0px;
      }
      > > > .el-table__header th {
        padding: 0;
        height: 30px;
        line-height: 30px;
      }
      > > > .el-table__fixed-right {
        height: 100% !important;
      }
      > > > .el-table__column-filter-trigger {
        line-height: 28px;
        i {
          font-size: 18px;
        }
      }
      > > > .el-table__row .cell {
        display: flex;
        align-items: center;
      }
      > > > .el-table__header .has-gutter .cell {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .salesclerk-dialog > > > .el-dialog .el-dialog__header {
      display: flex;
      align-items: center;
      height: 48px;
      background: #F7F8FA;
      padding: 0px 0px 0px 12px;
      .el-dialog__headerbtn {
        top: 15px;
      }
    }
    .look-dialog > > > .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
      margin-bottom: 0px;
    }
    .salesclerk-dialog {
      font-size: 14px;
      color: #606266;
    }
  }
</style>
